package com.xuanxu.blogs.framework.web.core.handler;

import com.xuanxu.blogs.framework.common.enums.HttpStatusEnum;
import com.xuanxu.blogs.framework.common.exception.BlogsBaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author XuanXu
 * @version 1.0
 * @date 2024-08-19 17:22
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BlogsBaseException.class)
    public ResponseEntity<String> blogsBaseExceptionHandler(BlogsBaseException bbe) {
        return new ResponseEntity<>(bbe.getMessage(), null, bbe.getStatus());
    }

    @ExceptionHandler(Throwable.class)
    public ResponseEntity<String> blogsBaseExceptionHandler(Throwable th) {
        return new ResponseEntity<>(th.getMessage(), null, HttpStatusEnum.UNKNOWN.getStatus());
    }
}
